package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import po.Employment;
import po.Order;
import service.TutorService;
import service.UserService;

public class IssueAction {
	private Order ord;
	private Employment employment;
	public void setOrd(Order ord) {
		this.ord = ord;
	}
	public Order getOrd() {
		return this.ord;
	}
	
	public void setEmployment(Employment employment) { 
		this.employment = employment;
	}
	public Employment getEmployment() {
		return this.employment;
	}
	
	//家教发布课程
	public String issue() {
		TutorService ts = new TutorService();
		//System.out.println(ord.getType()+" "+ord.getCourse()+" "+ord.getDate());
		//完善ord中的信息 包括发布者id name sex background
		//先取id-session
		HttpServletRequest request = ServletActionContext.getRequest();
		//得到用户id 正常登陆取值正常
		HttpSession session = request.getSession();
		int userID = (int) session.getAttribute("userID");
		//由用户id 取后三者信息
		ord.setPromulgatorID(userID); //这里设置的是家教的ID
		ts.setParam(ord);
		
		if(ts.issueCourse(ord)) {
			return "success";
		}else {
			return "fail";
		}
	}
	//家教修改课程
	//定义AJAX传入的四个参数-ordID在下面定义
	private String money;
	private String date;
	private String address;
	private String text;
	public void setMoney(String money) {
		this.money = money;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String modCourse() {
		//System.out.println("成功获得参数"+ordID+" "+money+" "+date+" "+address);
		TutorService ts = new TutorService();
		
		ts.modCourse(ordID, money, date, address,text);
		
		return "success";
	}
	//家教删除课程
	private int ordID;
	public void setOrdID(int ordID) {
		this.ordID = ordID;
	}
	public String deleteCourse() {
		TutorService ts = new TutorService();
		System.out.println(ordID);
		System.out.println("删除时获得id="+ordID);
		Order ord = new Order();
		ord.setOrderID(ordID); //设置主键
		ts.deleteCourse(ord);
		return "success";   
	}
	
	//用户发布招聘信息
	public String issueToTutor() {
		UserService us = new UserService();
		HttpServletRequest request = ServletActionContext.getRequest();
		//得到用户id 正常登陆取值正常
		HttpSession session = request.getSession();
		int userID = (int) session.getAttribute("userID");
		//由用户id 取后三者信息
		employment.setCostomerID(userID); //这里设置的是用户的ID
		
		if(us.issue(employment)) {
			return "success";
		}else {
			return "fail";
		}
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
}
